package main

import (
	"fmt"
	"os"
	codecs "sanguo/codec/cs"
	"sanguo/node/client/dispatcher"
	"sanguo/node/client/login"
	cs_msg "sanguo/protocol/cs/message"

	"github.com/golang/protobuf/proto"
	"github.com/sniperHW/kendynet"
)

func main() {

	if len(os.Args) < 3 {
		fmt.Printf("usage createRole userID addr\n")
		return
	}

	userID := os.Args[1]
	addr := os.Args[2]

	login.Login(userID, addr, func(session kendynet.StreamSession, d *dispatcher.Dispatcher, msg *codecs.Message, err error) {
		if nil != err {
			fmt.Println(err)
		} else {
			gameLoginToC := msg.GetData().(*cs_msg.GameLoginToC)
			fmt.Println("CreateRole：", gameLoginToC)
			if gameLoginToC.GetCode() == cs_msg.EnumType_OK {

				fmt.Printf("角色名字:")
				var name string
				fmt.Scan(&name)
				req := &cs_msg.CreateRoleToS{
					Face:      proto.Int32(14011),
					Hair:      proto.Int32(14021),
					HairColor: proto.Int32(0),
					EyeColor:  proto.Int32(14031),
					Cloth:     proto.Int32(14051),
					Outline:   proto.Int32(10001),
					Name:      proto.String(name),
					Portrait:  proto.Int32(100001),
				}

				session.Send(codecs.NewMessage(uint16(0), req))
				d.Register(&cs_msg.CreateRoleToC{}, true, func(args []interface{}) {
					resp := args[1].(*codecs.Message).GetData().(*cs_msg.CreateRoleToC)
					fmt.Println(resp)
				})
			}
		}
	})

	sigStop := make(chan bool)
	_, _ = <-sigStop
}
